<?php
class core_signal {
	
	static private $signal = array();
	
	static public function SetHandle($signal, $function)
	{
		self::$signal[$signal][] = $function;
	}
	
	static public function RmHandle($signal, $function)
	{
		if (isset(self::$signal[$signal]) && in_array($function, self::$signal[$signal]))
		{
			$key = array_keys(self::$signal[$signal], $function);
			unset(self::$signal[$signal][$key[0]]);
		}
	}
	
	static public function NewSignal($signal, &$args = array())
	{
		$ret = array();
		if (isset(self::$signal[$signal]) && is_array(self::$signal[$signal]))
			foreach (self::$signal[$signal] as $function)
			{
				$ret[] = call_user_func_array($function, $args);
			}
		return $ret;
	}
	
	static public function SmpSignal($signal)
	{
		$args = func_get_args();
		unset($args[0]);
		self::NewSignal($signal, $args);
	}
}